
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right" class="breadNav">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>用户管理</el-breadcrumb-item>
      <el-breadcrumb-item>用户列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!--
      输入框
      gutter用来显示间距;
      slot-scope:自定义列
    -->
    <el-row :gutter="20">
      <el-col :span="8">
        <el-input
          placeholder="请输入内容"
          v-model="input5"
          class="input-with-select"
        >
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="searhList"
          ></el-button>
        </el-input>
      </el-col>
      <el-col :span="3">
        <el-button @click="showAddUsersDialoge">添加用户</el-button>
      </el-col>
    </el-row>
    <!-- 列表渲染页 -->
    <el-table :data="dataList" style="width: 100%">
      <el-table-column
        prop="username"
        label="姓名"
        width="180"
      ></el-table-column>
      <el-table-column prop="email" label="邮箱" width="180"></el-table-column>
      <el-table-column prop="mobile" label="电话"></el-table-column>
      <el-table-column label="用户状态">
        <!-- scope.row可以拿到当前行的数据,element组件已经封装好的 -->
        <template slot-scope="scope">
            <el-switch
            style="display: block"
            v-model="scope.row.mg_state" @change="changeState(scope.row)">
          </el-switch>
        </template>

      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
            <el-button
            size="mini"
            plain
            type="primary"
            icon="el-icon-edit"
            @click="showEditDialoge(scope.row)"
          ></el-button>
          <el-button
            size="mini"
            plain
            type="danger"
            icon="el-icon-delete" @click='delUsers(scope.row.id)'
          ></el-button>
          <el-button size="mini" plain type="success" icon="el-icon-check"
          @click='showAssignDialoge(scope.row)'>分配角色</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <!--
    分页栏
      total：数据的总条数
      current-page:当前页数
      page-size:每页显示的条数
      current-change: 点击具体的页数时会触发
    -->
    <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
      :current-page="currentPage"
      :page-size="2"
      @current-change="setPagination"
    ></el-pagination>

    <!-- 添加用户对话框 -->
    <el-dialog title="添加用户" :visible.sync="addUsersDialoge" >
        <el-form :model="addUsersForm" label-width="80px" :rules='rules' ref="addUsersForm">
            <el-form-item label="用户名" prop='username' >
                <el-input v-model="addUsersForm.username" autocomplete="off"></el-input>
              </el-form-item>
            <el-form-item label="密码" prop='password' >
                <el-input v-model="addUsersForm.password" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="邮箱" prop='email'>
                  <el-input v-model="addUsersForm.email" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="手机" prop='mobile'>
                    <el-input v-model="addUsersForm.mobile" autocomplete="off"></el-input>
                  </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="addUsersDialoge = false">取 消</el-button>
          <el-button type="primary" @click="confirmToAdd">确 定</el-button>
        </div>
      </el-dialog>




    <!-- 分配角色对话框 -->
    <el-dialog title="分配角色" :visible.sync="assignRolesDialoge">
        <el-form :model="assignRolesForm" label-width="80px" >
          <el-form-item label="用户名">
              <el-tag>{{assignRolesForm.username}}</el-tag>
          </el-form-item>
          <el-form-item label="角色列表">
            <el-select v-model="assignRolesForm.rid" placeholder="请选择角色">
              <!-- label是展示,value是选中的绑定的值，是id -->
              <el-option :label="item.roleName" :value="item.id" v-for="item in rolesList" :key="item.id"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="confirmToAddRoles">确 定</el-button>
        </div>
      </el-dialog>

      <!-- 编辑用户对话框 -->
      <el-dialog title="编辑用户" :visible.sync="editUsersDialoge" >
          <el-form :model="editUsersForm" label-width="80px">
              <el-form-item label="用户名">
                <el-tag type="info">{{editUsersForm.username}}</el-tag>
              </el-form-item>
            </el-form>
          <el-form :model="editUsersForm" label-width="80px">
            <el-form-item label="邮箱">
              <el-input v-model="editUsersForm.email" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="电话">
                <el-input v-model="editUsersForm.mobile" autocomplete="off"></el-input>
              </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="editUsersDialoge = false">取 消</el-button>
            <el-button type="primary" @click="confirmToEdit">确 定</el-button>
          </div>
        </el-dialog>
  </div>
</template>
